﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Leffaetsin.Models;
using RestSharp;

namespace Leffaetsin.Services.Providers.ShowProviders
{
    internal class FinnkinoProvider : AbstractShowProvider
    {
        public override IEnumerable<GetMovieDto> GetShows(string areaName)
        {
            var area = GetArea(areaName);
            if (area == null)
                return Enumerable.Empty<GetMovieDto>();

            var client = new RestClient("http://www.finnkino.fi/");
            var request = new RestRequest("xml/Schedule/?area=" + area.ID, Method.GET);

            IRestResponse<FinnkinoShows> finnkinoMovies = client.Execute<FinnkinoShows>(request);
            return finnkinoMovies.Data.Shows.Where(m => m.Genres != "Ooppera");
            // TODO: strippaa leffat, joilla genrenä Ooppera, pois
        }

        private TheatreArea GetArea(string areaName)
        {
            return GetAreas().FirstOrDefault(a => a.Name.ToLowerInvariant() == areaName.ToLowerInvariant());
        }

        public override IEnumerable<TheatreArea> GetAreas()
        {
            var client = new RestClient("http://www.finnkino.fi/");
            var request = new RestRequest("xml/TheatreAreas/", Method.GET);

            IRestResponse<List<TheatreArea>> finnkinoAreas = client.Execute<List<TheatreArea>>(request);

            return finnkinoAreas.Data.Skip(1).Where(a => !a.Name.Contains(":"));
        }
    }
}